//
//  UITextField+Validator.m
//  iNote1
//
//  Created by tjufe on 2017/7/17.
//  Copyright © 2017年 zhen-PC. All rights reserved.
//

#import "UITextField+Validator.h"

@implementation UITextField (Validator)

-(BOOL)isNotEmpty{
    return ![self.text isEqualToString:@""];
}

-(BOOL)validate:(NSString *)inputStr{
    
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",inputStr];
    return [predicate evaluateWithObject:self.text];
}

#pragma mark - 具体验证函数

-(BOOL)validateUserName{
    
    return [self validate:@"^\\d{11}$"];
}
-(BOOL)validateEmail{
    return [self validate:@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\/[A-Za-z]{2,4}"];
    
}
-(BOOL)validatePhoneNumber{
    
    return [self validate:@"^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$"];
}
-(BOOL)validatePassWord{
    
    return [self validate:@"{^[A-Za-z0-9]{6,20}$}"]; //6~20位字符，不能存在空格
}
//6位验证码
-(BOOL)validateSixVerificationCode{
    return [self validate:@"^\\d{6}$"];
}
//姓名
-(BOOL)validateName{
    
    return [self validate:@"/^[\u4E00-\u9FA5A-Za-z]+$/"];
    
}



+ (BOOL)checkPassword:(NSString *) password
{
    NSString *pattern = @"^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9]{6,18}";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
    BOOL isMatch = [pred evaluateWithObject:password];
    return isMatch;
    
}







@end
